﻿using HNRoadFormatConverter.Commons;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace HNRoadFormatConverter.MyConfig
{
    public class Config
    {
        /// <summary>
        /// 皮肤
        /// </summary>
        public string DefaultSkin { get; set; }
        
        /// <summary>
        /// 用户文件夹
        /// </summary>
        public string UserPath { get; set; }

        public string NowModel { get; set; }
    }
    public class ConfigManager
    {
       static private LogHelper _log = new LogHelper(type: typeof(Config));
        public static Config Config { get; set; }
        private static string jsonConfigPath =AppDomain.CurrentDomain.BaseDirectory+ "config\\config.json";
        static ConfigManager()
        {
            try
            {
                string jsonTxt = File.ReadAllText(jsonConfigPath);
                Config = JsonHelper.FromJSON<Config>(jsonTxt);
            }
            catch (Exception ex)
            {
                _log.Error(jsonConfigPath+"\\n配置文件读取失败");
                throw ex;
            }
           
        }
        public static Config GetConfig()
        {
            return Config;
        }

        public static void SaveConfig()
        {
            string jsonStr= JsonHelper.ToJSON(Config);

            FileHerper.WriteFileMemory(FileHerper.getMemoryStream(jsonStr), jsonConfigPath, typeof(ConfigManager).ToString());
        }
        private ConfigManager()
        {

        }
    }

}
